home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat5 / elspec.z / elspec
Encoding:
Text File  |  2002-10-03  |  23.4 KB  |  630 lines

  1. ELSPEC(5)                                              Last changed: 4-6-99
  2.  
  3.  
  4. NNAAMMEE
  5.      eellssppeecc - ELF layout specification
  6.  
  7. IIMMPPLLEEMMEENNTTAATTIIOONN
  8.      IRIX systems
  9.  
  10. DDEESSCCRRIIPPTTIIOONN
  11.      This man page describes the ELF Layout Specification (ELSPEC) language
  12.      implemented by lldd(1). ELSPEC allows users to specify the exact layout
  13.      of object files, programs, and shared objects.
  14.  
  15.      It is often desirable to specify the exact layout of an executable
  16.      file.  Some of the uses of this might be embedded systems layout,
  17.      thread-local data layout, reducing cache conflicts, reducing false
  18.      sharing, reducing memory utilization.
  19.  
  20. IINNVVOOKKIINNGG LLAAYYOOUUTT SSPPEECCIIFFIICCAATTIIOONN
  21.      An ELSPEC file can be specified to the linker on the compiler command
  22.      line using the --WWll option and the lldd(1) command's --eellssppeecc option.
  23.  
  24.      The following examples shows the cccc(1) and lldd(1) commands specifying
  25.      an ELSPEC file:
  26.  
  27.           cc -Wl,-elspec,_e_l_s_f_i_l_e ......
  28.  
  29.      or
  30.  
  31.           ld -elspec _e_l_s_f_i_l_e ......
  32.  
  33.      You can get a sample ELSPEC file for the default link by using the
  34.      lldd(1) command's --eellssmmaapp option.  The following example shows the cccc(1)
  35.      and lldd(1) commands with the --eellssmmaapp option:
  36.  
  37.           cc -Wl,-elsmap ...
  38.  
  39.      or
  40.  
  41.           ld -elsmap ...
  42.  
  43. BBAASSIICC BBUUIILLDDIINNGG BBLLOOCCKKSS
  44.      The basic units that the linker manipulates are called _i_n_p_u_t _s_e_c_t_i_o_n_s.
  45.      Each object file can have several input sections with familiar names
  46.      such as ..tteexxtt, ..ddaattaa, ..bbssss, and so on.  The correctness of compiled
  47.      code can depend on the exact layout of code and data within a section,
  48.      but it never depends on the relative layout between sections.  For
  49.      that reason, the linker does not rearrange or change the contents of
  50.      any individual input section with the exception of uninitialized
  51.      common variables.
  52.  
  53.      Uninitialized common variables, for which space is allocated by the
  54.      linker, are not allocated to any input section.  These can be
  55.      manipulated freely, but they cannot be split into pieces by an ELSPEC.
  56.      You get a COMMON variable by using a Fortran COMMON statement or from
  57.      C data variables declared at file scope in files that have been
  58.      compiled with either ..BB --cccckkrr or ..BB --ccoommmmoonn.
  59.  
  60.    SSeeggmmeennttss
  61.      Input sections are linked together contiguously into output sections.
  62.      Output sections are organized in an ELF file into loadable segments
  63.      specified in the program header.  For more information, see the eellff(4)
  64.      man page.
  65.  
  66.      Segments represent a contiguous portion of the file to be loaded into
  67.      memory as it is, with possibly the addition of extra memory at the
  68.      end.
  69.  
  70.    PPLLAACCEEMMEENNTT RRUULLEESS
  71.      An ELSPEC allows you to specify the following:
  72.  
  73.      * The placement of input sections within output sections.
  74.  
  75.      * The placement of output sections within segments.
  76.  
  77.      Rules exist regarding default placement.  The following rules describe
  78.      when a section from an input file is placed in the output file:
  79.  
  80.      1. If the section (and object and archive) is mentioned explicitly, it
  81.         is placed as specified.
  82.  
  83.      2. If there is a section specified in the map with the same name, with
  84.         ddeeffaauulltt as one of its contents, and with matching attributes, it is
  85.         placed there.
  86.  
  87.         The input section maintains its layout position relative to other
  88.         listed contents.  If there is more than one default-placed input
  89.         section, space is allocated for them in the order encountered.  If
  90.         the attributes of the input section do not match those specified in
  91.         the map, it is an error.
  92.  
  93.      3. If there is a segment specified in the map with matching attributes
  94.         that has specified ddeeffaauulltt as one of its contents, the input
  95.         section is placed in an output section with the same name and
  96.         attributes.  The input section maintains its layout position
  97.         relative to other listed contents.  If there is more than one
  98.         default-placed input section, space is allocated for them in the
  99.         order encountered.  If the attributes of the input section do not
  100.         match those specified in the map or those of another default input
  101.         section, it is an error.
  102.  
  103.      4. If an input object is listed as a segment content without mention
  104.         of specific input sections, all sections with appropriate
  105.         attributes are merged by name and laid out in the order
  106.         encountered.
  107.  
  108.      5. The linker manages file layout in any fashion it sees fit.
  109.  
  110.      6. Specifying hheeaaddeerrss or specifying ddeeffaauulltt as contents of a segment
  111.         allows (but does not require) the inclusion of headers, such as the
  112.         ELF header and the program header, into that segment.  Specifying
  113.         nnoohheeaaddeerrss forbids the inclusion of headers into that segment
  114.  
  115.      7. Linker-generated sections are placed into a segment with matching
  116.         attributes that has llddggeenn specified as its segment contents.
  117.         Specific linker-generated sections can be placed by using $$llddoobbjj as
  118.         the object name.  When a non-optional, linker-generated section has
  119.         no place to be loaded, an error is generated unless the
  120.         $$iiggnnoorreellddggeenn ELSPEC variable is set to ttrruuee.  For more information,
  121.         see the EELLSSPPEECC VVaarriiaabblleess section in this man page.
  122.  
  123.      8. Command line options are available to override the general rules
  124.         stated on this man page.
  125.  
  126.      9. Overlaps in virtual space or physical space are reported unless at
  127.         least one of the segment descriptions has specified an overlap with
  128.         the other, or unless the $$iiggnnoorreeoovveerrllaappss ELSPEC variable is set to
  129.         ttrruuee.
  130.  
  131.      10.The name, type, and flags of an output section uniquely determine a
  132.         section.  Specifying more than one such section in the file yields
  133.         unpredictable results.
  134.  
  135. SSYYNNTTAAXX
  136.      The following sections describe the syntax of an ELSPEC file.
  137.  
  138.    OOvveerrvviieeww
  139.      An ELSPEC file consists of the following parts, in the following
  140.      order:
  141.  
  142.      1. A list of global variable settings
  143.  
  144.      2. A list of symbol attribute specifications
  145.  
  146.      3. A list of segment specifications
  147.  
  148.      Using modified Backus-Naur Form (BNF), this can be depicted as
  149.      follows:
  150.  
  151.           <layoutspec> ::= <globals> <symlist> <seglist>;
  152.  
  153.    SSeeggmmeennttss
  154.      Segments are the basic runtime building blocks and are comprised of
  155.      one or more sections.  The content of each segment is contiguous.
  156.      Sections within a segment must have compatible attributes.
  157.  
  158.      The following BNF shows how a segment is organized:
  159.  
  160.  <segdef>  ::= beginseg <segname> <segattr> contents <segcontents> endseg
  161.            ;
  162.  
  163.  <segname> ::= /* empty */
  164.              | <idstring>
  165.            ;
  166.  
  167.  <segattr> ::= /* empty */
  168.              | <segattr> segtype <segtype>
  169.              | <segattr> vaddr <address>
  170.              | <segattr> paddr <address>
  171.              | <segattr> filesz <size>
  172.              | <segattr> memsz <size>
  173.              | <segattr> segflags <segflags>
  174.              | <segattr> segalign <number>
  175.              | <segattr> prepad <number>
  176.            ;
  177.  
  178.            WHERE:
  179.               "segtype"  is the segment type (see the following BNF
  180.                          for <segtype>).
  181.  
  182.               "vaddr"    is the virtual address.
  183.  
  184.               "paddr"    is the physical address.
  185.  
  186.               "filesz"   is the size of the segment in the file.
  187.  
  188.               "memsz"    is the size of the segment at runtime in memory.
  189.  
  190.               "segflags" is the bit mask of flags for this segment (see the
  191.                          following BNF for <segflags>).
  192.  
  193.               "segalign" is the alignment of the segment.
  194.  
  195.               "prepad"   is the amount of padding to put at the beginning
  196.                          of the segment.
  197.  
  198.  <segtype> ::= noload
  199.              | <number>
  200.              | LOAD
  201.              | REL
  202.            ;
  203.  
  204.            WHERE:
  205.               "noload"   indicates that the section should not be
  206.                          loaded at runtime.  This is a pseudo segment
  207.                          used to group nonloadable sections.
  208.  
  209.               "<number>" is the hexadecimal number for the section type.
  210.                          See the ELF ABI for possible segment types.
  211.  
  212.               "LOAD"     indicates that the segment should be loaded at
  213.                          runtime.  DEFAULT.
  214.  
  215.               "REL"      indicates relocatable output.
  216.                          See the following <segflags>.
  217.  
  218.  <segflags> ::= /* empty, default settings are RWX */
  219.               | <segflags> R
  220.               | <segflags> W
  221.               | <segflags> X
  222.               | <segflags> L
  223.             ;
  224.  
  225.             WHERE:
  226.                "R" is readable.
  227.                "W" is writable.
  228.                "X" is executable.
  229.                "L" is thread local.
  230.  
  231.    SSeeggmmeenntt CCoonntteennttss
  232.      The contents of a segment are usually in the form of output sections.
  233.      These section are further specified to contain input sections (see
  234.      following) and are laid out in the order specified, building upwards
  235.      in virtual address space.
  236.  
  237.      The segment contents (sseeggccoonntteennttss) are defined as follows:
  238.  
  239. <segcontents> ::= /* empty */
  240.                 | <segcontents> <outsection>
  241.                 | <segcontents> noheaders
  242.                 | <segcontents> default
  243.                 | <segcontents> default_gprel
  244.                 | <segcontents> ldgen
  245.                 ;
  246.  
  247.                 WHERE:
  248.                   "<outsection>"  is a specific output section.  For more
  249.                                   information, see the Output Sections
  250.                                   section of this man page.
  251.  
  252.                   "noheaders"     excludes ELF, PROGRAM, and SECTION headers.
  253.  
  254.                   "default"       allows the linker to place input sections
  255.                                   with compatible attributes that are not
  256.                                   otherwise mentioned in the current segment.
  257.                                   This is accomplished by creating distinct
  258.                                   output sections for each unique set of
  259.                                   section type, flags, and section name,
  260.                                   and placing it in the best segment that
  261.                                   has specified "default" as one of its
  262.                                   segment contents.
  263.  
  264.                   "default_gprel" specifies all output sections that
  265.                                   are GP-relative.  GP is the Global Pointer.
  266.  
  267.                   "ldgen"         consists of linker-generated output
  268.                                   sections.
  269.  
  270.    OOuuttppuutt SSeeccttiioonnss
  271.      Output sections are a convenient way to group material within a
  272.      segment.
  273.  
  274.      For example, if you have decided to have read-only data and program
  275.      text in the same segment, but within that segment, you want to have
  276.      all the read-only data together and all the text together.  You can
  277.      define two output sections, named ..rrddaattaa and ..tteexxtt, and place them
  278.      both within a single segment.
  279.  
  280.      Most of the terms used in the section syntax maps to the ELF section
  281.      header structure fields, which are as follows:
  282.  
  283.      FFiieelldd nnaammee          CCoonntteenntt
  284.  
  285.      sshh__nnaammee             Section name
  286.  
  287.      sshh__ttyyppee             Section type
  288.  
  289.      sshh__ffllaaggss            Section flags
  290.  
  291.      sshh__aaddddrr             Address of first byte, or zero
  292.  
  293.      sshh__ooffffsseett           File offset of section
  294.  
  295.      sshh__ssiizzee             Section's size in bytes
  296.  
  297.      sshh__lliinnkk             Table index link (section specific)
  298.  
  299.      sshh__iinnffoo             Extra information (section specific)
  300.  
  301.      sshh__aaddddrraalliiggnn        Address alignment constraint
  302.  
  303.      sshh__eennttssiizzee          Size of fixed-size entries in section, or zero
  304.  
  305.      The output sections are defined as follows:
  306.  
  307. <outsection> ::= beginscn <idstring> <scnattr> <scnspecial>
  308.                 <scncontents> endscn
  309.                | beginscn <idstring> relfor <idstring> endscn
  310.                | beginscn <idstring> relafor <idstring> endscn
  311.              ;
  312.  
  313. <scnattr>    ::= /* empty string */
  314.                | <scnattr> scntype <scntype>
  315.                | <scnattr> scnflags <scnflags>
  316.                | <scnattr> scnsize <size>
  317.                | <scnattr> link <number>
  318.                | <scnattr> info <number>
  319.                | <scnattr> scnalign <number>
  320.                | <scnattr> entsize <number>
  321.              ;
  322.  
  323. <scntype>    ::= PROGBITS
  324.                | NOTE
  325.                | NOBITS
  326.                | <number>
  327.              ;
  328.  
  329.              WHERE:
  330.                 "PROGBITS" means the section will be in memory at runtime.
  331.  
  332.                 "NOTE"     means the section with marked as note section.
  333.  
  334.                 "NOBITS"   means the contents of the section may not take up
  335.                            any space in the file, but it is filled out at
  336.                            runtime.
  337.  
  338.                 "<number>" is the hexadecimal number that represents
  339.                            the section type.  (See the MIPS ABI).
  340.  
  341. <scnflags>    ::= <scnflaglist>
  342.                 | <number>
  343.                 | none
  344.               ;
  345.  
  346. <scnflaglist> ::= /* empty */
  347.                 | <scngflaglist> WRITE
  348.                 | <scnflaglist> ALLOC
  349.                 | <scnflaglist> EXECINSTR
  350.                 | <scnflaglist> GPREL
  351.                 | <scnflaglist> MERGE
  352.                 | <scnflaglist> NOSTRIP
  353.                 | <scnflaglist> LOCAL
  354.               ;
  355.  
  356.               WHERE:
  357.                  "WRITE"     means that the contents are writable.
  358.  
  359.                  "ALLOC"     means that the contents will be in memory.
  360.  
  361.                  "EXECINSTR" means that the contents are executable
  362.                              instrutions.
  363.  
  364.                  "GPREL"     means that the contents are within 64K bytes
  365.                              of the value contained in the GP register
  366.                              (short data).
  367.  
  368.                  "MERGE"     means that the contents of the section can
  369.                              be merged with other similar sections.  For
  370.                              example, literal sections.
  371.  
  372.                  "NOSTRIP"   means that this section should not be stripped
  373.                              from the file.
  374.  
  375.                  "LOCAL"     means that the contents are thread-local data.
  376.  
  377.      Layout specification for relocatable links is supported; for
  378.      information on these see the --rr option on the lldd(1) man page.
  379.  
  380.      Unlike other types of output sections, the contents of relocation
  381.      sections cannot be freely specified.  Rather, the contents of a given
  382.      rreellffoorr section are determined relative to some other output section.
  383.      For example, the following section contains all the rel-type
  384.      relocations for the output section named ..mmyytteexxtt:
  385.  
  386.           beginscn .rel.mytext relfor .mytext endscn
  387.  
  388.      Relocation sections can be given any name, but the relocation must be
  389.      preceded by the section to which the relocations are relative.
  390.  
  391.    IInnppuutt sseeccttiioonnss
  392.      Input sections are the basic building blocks that the linker
  393.      manipulates.  Each object file read by the linker can contain several
  394.      of these input sections.  The ELSPEC file works by specifying the
  395.      arrangement of these input sections.  You can specify input sections
  396.      by either attempting to specify the section directly or by specifying
  397.      an external symbol name.  Specifying an external symbol name has the
  398.      effect of specifying the section in which that symbol definition
  399.      resides.  These two methods of specification are defined as follows:
  400.  
  401.           <item> ::= <inputscn>
  402.                    | <symspec>
  403.                  ;
  404.  
  405.      Sometimes the attributes of an input section are not compatible with
  406.      those of the enclosing output section.  In the BNF that follows, you
  407.      see different input section specifications categorized as either
  408.      specific or generic.  Conflicts are handled as follows:
  409.  
  410.      * If a specific mention conflicts with default output section
  411.        attributes, the output section attributes are promoted to be
  412.        compatible.
  413.  
  414.      * If a specific mention conflicts with user-specified output section
  415.        attributes, the input section is included with a warning, but the
  416.        output section attributes are not altered.
  417.  
  418.      * If a generic mention conflicts with output section attributes, the
  419.        input section is not included in the output section, regardless of
  420.        whether the output sections attributes were user-specified or not.
  421.  
  422.      In the following BNF, the <<iiddssttrriinngg>> specifies the name of the input
  423.      section.  If no name is specified, all sections from the mentioned
  424.      object with matching attributes are selected.
  425.  
  426.     <inputscn> ::= sec <idstring>             /* specific mention */
  427.                  | sec <idstring> in <object> /* specific mention */
  428.                  | <object>                   /* generic mention */
  429.                ;
  430.  
  431.     <object>   ::= obj[ect] <idstring> ( <idstring> )
  432.                  | obj[ect] <idstring>
  433.                  | ar[chive] <idstring>
  434.                  | ldobj                      /* for specifying
  435.                                               /* linker-defined sections */
  436.                ;
  437.  
  438.     <symspec>  ::= sym <idstring> in <inputscn>
  439.                  | sym <idstring>
  440.                ;
  441.  
  442.    EELLSSPPEECC VVaarriiaabblleess
  443.      The linker uses the values contained in various ELSPEC variables when
  444.      laying out your program.  These variables are as follows:
  445.  
  446.           <globals>   ::= /* NULL */
  447.                         | globals set_global
  448.                       ;
  449.  
  450.           <set_global ::= <gsize> = <size>
  451.                         | <gbool> = <boolean>
  452.                       ;
  453.  
  454.           <gsize>     ::= $blocksize
  455.                         | $cachesize
  456.                         | $pagesize
  457.                         | $cachelinesize
  458.                       ;
  459.  
  460.           <gbool>     ::= $ignoreldgen
  461.                         | $r4kbugfix
  462.                         | $ignoreoverlaps
  463.                       ;
  464.  
  465.    BBaassee DDaattaa TTyyppeess
  466.      The base data types are defined as follows:
  467.  
  468.           <size>     ::= <number>
  469.                        | <number> K
  470.                        | <number> M
  471.                      ;
  472.  
  473.           <address>  ::= <number>
  474.  
  475.           <number>   ::= 0x[0-9a-f]+ /* Hex number */
  476.                        | 0[0-7]+     /* Octal number */
  477.                        | [0-9]+      /* decimal number */
  478.                      ;
  479.  
  480.           <boolean>  ::= true
  481.                        | false
  482.                      ;
  483.  
  484.           <idstring> ::= [a-zA-Z0-9$_.]+
  485.                        | "<any string>"
  486.                      ;
  487.  
  488.    CCoommmmeennttss
  489.      If the pound character (##) appears in a layout specification (except
  490.      when within a string specified with quotation marks ("""")), the
  491.      remainder of the line, including the ## is treated as a comment and is
  492.      ignored.
  493.  
  494. EEXXAAMMPPLLEESS
  495.      Example 1. This is the default link specification.  Using it should
  496.      give the same result as not using the --eellssppeecc option on the lldd(1)
  497.      command.
  498.  
  499.           beginseg
  500.                   name text
  501.                   segtype LOAD
  502.                   vaddr 0x10000000
  503.                   segflags R X
  504.                   segalign 0x10000
  505.  
  506.                   contents default
  507.           endseg
  508.           beginseg
  509.                   name data
  510.                   segtype LOAD
  511.                   segflags R W X
  512.                   segalign 0x1000
  513.  
  514.                   contents default
  515.           endseg
  516.           beginseg
  517.                   name noload
  518.                   segtype noload
  519.  
  520.                   contents default
  521.           endseg
  522.  
  523.      Example 2.  This link specification gives the COMMON symbol aa__ an
  524.      alignment of 128 bytes.  This prevents false sharing, among other
  525.      things.
  526.  
  527.           beginseg
  528.               segtype LOAD
  529.               segflags R X
  530.           #   vaddr 0x10000000
  531.               segalign 0x1000
  532.               contents
  533.               default
  534.           endseg
  535.  
  536.           beginseg
  537.               segtype LOAD
  538.               segflags R W
  539.           #   vaddr 0x10011000
  540.               segalign 0x1000
  541.               contents
  542.               default
  543.               beginscn .mybss
  544.                   scntype NOBITS
  545.                   scnflags ALLOC WRITE
  546.                   scnalign 0x80
  547.                   sym a_
  548.               endscn
  549.           endseg
  550.  
  551.      Example 3.  If data needs to be loaded relative to the Global Pointer
  552.      (the ggpprreell area), the ELSPEC file must contain information regarding
  553.      this data.  When this information is missing from the ELSPEC file, the
  554.      system generates the following messages:
  555.  
  556.        ld32: FATAL 173:  No gprel area specified in elspec file.
  557.               Try using "default_gprel" after the data section declaration.
  558.               See ELSPEC(5)
  559.        ld32: INFO 152: Output file removed because of error.
  560.  
  561.      To correct the file, add the following line:
  562.  
  563.           default_gprel
  564.  
  565.      Here is the corrected ELSPEC file:
  566.  
  567.           beginseg
  568.               segtype LOAD
  569.               segflags R W X
  570.               vaddr 0x88500000
  571.               segalign 0x1000
  572.               contents
  573.               beginscn .text
  574.                   scntype PROGBITS
  575.                   scnflags ALLOC EXECINSTR
  576.                   scnalign 0x10
  577.                   section .text
  578.               endscn
  579.           endseg
  580.           beginseg
  581.               segtype LOAD
  582.               segflags R W
  583.               vaddr 0xa85a5000
  584.               segalign 0x1000
  585.               contents
  586.               beginscn .rodata
  587.                   scntype PROGBITS
  588.                   scnflags ALLOC WRITE
  589.                   scnalign 0x8
  590.                   section .rodata
  591.               endscn
  592.               beginscn .rdata
  593.                   scntype PROGBITS
  594.                   scnflags ALLOC WRITE
  595.                   scnalign 0x8
  596.                   section .rdata
  597.               endscn
  598.               beginscn .data
  599.                   scntype PROGBITS
  600.                   scnflags ALLOC WRITE
  601.                   scnalign 0x8
  602.                   section .data
  603.               endscn
  604.               default_gprel                # SPECIFIES gprel LOADING
  605.               beginscn .bss
  606.                   scntype NOBITS
  607.                   scnflags ALLOC WRITE
  608.                   section .bss
  609.               endscn
  610.               beginscn .MIPS.options
  611.                   scntype 0x7000000d
  612.                   scnflags ALLOC NOSTRIP
  613.                   scnalign 0x8
  614.                   section .MIPS.options
  615.               endscn
  616.               beginscn .reginfo
  617.                   scntype NOBITS
  618.                   scnflags ALLOC NOSTRIP
  619.                   scnalign 0x8
  620.                   section .reginfo
  621.               endscn
  622.           endseg
  623.  
  624. SSEEEE AALLSSOO
  625.      eellffdduummpp(1), lldd(1)
  626.  
  627.      eellff(4)
  628.  
  629.      This man page is available only online.
  630.